package ding

//钉钉请求限制，每秒40次

import (
	"encoding/json"
	"fjj/tool/config"
	universal "fjj/tool/universal"
	"fmt"
)

/*
获取ACCESSTOKEN

错误返回空字符
*/

func GetAccessToken() string {
	cfg := config.GetConfig()

	url := fmt.Sprintf("https://oapi.dingtalk.com/gettoken?appkey=%s&appsecret=%s",
		cfg.Ding.AppKey, cfg.Ding.AppSecret)

	s := universal.Get(&url)
	println("企业内部应用的access_token BODY：", s)

	m := access_token_back{}
	err := json.Unmarshal([]byte(s), &m)
	if err != nil {
		fmt.Println("AccessToken JSON Umarshal failed:", err)
		return ""
	}

	return m.AccessToken
}
